<?php
// 打开全局session
session_start();
// 如果没有登录，跳转到主页
if (!isset($_SESSION["role"]))
    header("location:../index.php");
?>

<!-- 记录默认返回多少条未选信息 -->
<?php
//session_start();
if (isset($_POST['recNumber']))
    $_SESSION["recNumber"]=trim($_POST['recNumber']);
if(isset($_SESSION["recNumber"]))
    $RecNumPerPage=$_SESSION["recNumber"];
else
    $RecNumPerPage=10;
?>
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=UTF-8" />
<title>社团信息显示</title>
</head>
<body>
<?php //echo "<center><br /><a href='showsession.php'>返回功能列表</a></center>"; ?>
<center>点击社团编码链接可以查看社团详细信息</center>
<center>
    <form method="POST" action="showunselected.php">
        <select name="recNumber" >
            <?php
            for($i=3;$i<=10;$i++){
                if ($i==$RecNumPerPage)
                    echo  "<option value=".$i." selected>每页显示".$i."条记录</option>";
                else
                    echo  "<option value=".$i.">每页显示".$i."条记录</option>";
            }
            ?>
        </select>
        <input type="submit" value="刷新" name="ok">
    </form>
</center>
<table width="540" border="1" align="center" cellpadding="0" cellspacing="1">
    <tr bgcolor="#0066CC"> 
      <td width="80" align="center"><font color="#FFFFFF"><b>编码</b></font></td>
      <td width="220" align="center"><font color="#FFFFFF"><b>社团名称</b></font></td>
      <td width="100" align="center"><font color="#FFFFFF"><b>类别</b></font></td>
      <td width="80" align="center"><font color="#FFFFFF"><b>级别</b></font></td>
      <td width="80" align="center"><font color="#FFFFFF"><b>需求人数</b></font></td>
    </tr>

<!-- 数据库查询学生未选的社团有哪些 -->
<?php
include("../functions/db_conn.php");
//$ShowClass_sql = "SELECT * FROM course";
//$stuno='17010001';
$stuno=$_SESSION["username"];
$ShowSoci_sql = "SELECT * FROM soci s, department d WHERE s.departNo = d.departNo";
$ShowSoci_sql .=" AND s.SociNo NOT IN (SELECT SociNo FROM StuSoci WHERE StuNo='$stuno')";
$ShowSoci_sql .=" ORDER BY s.SociNo;";
$ShowSociResult = mysql_query($ShowSoci_sql);
$Sum = mysql_num_rows($ShowSociResult);
if ($Sum>0)
{
    if (isset($_GET['FirstRecNo']))
        $FirstRecNo=$_GET['FirstRecNo'];
    else
        $FirstRecNo=0;
    $MaxRecNo = $FirstRecNo + $RecNumPerPage;
    mysql_data_seek($ShowSociResult,$FirstRecNo);
    if ($Sum<$MaxRecNo)
        $recs=$RecNumPerPage-($MaxRecNo-$Sum);  //当前页需要显示的记录数
    else
        $recs=$RecNumPerPage;
    for($i=0;$i<$recs;$i++)
   {
       $row = mysql_fetch_array($ShowSociResult);
       if ($i%2 == 0) 
           echo "<tr bgcolor='#DDDDDD'  align='center'>";
       else
           echo "<tr align='center'>";
       echo "<td width='80'><a href='showmysoci.php?SociNo=".$row['SociNo']."'>".$row['SociNo']."</a></td>";
       echo "<td width='220'>".$row['SociName']."</td>";
       echo "<td width='80'>".$row['Kind']."</td>";
       echo "<td width='80'>".$row['Level']."</td>";
       echo "<td width='80'>".$row['LimitNum']."</td>";
       echo "</tr>";
    }
} 
?>
</table>
<!-- 分页显示 -->
<table width="400" border="0" align="center">
    <tr>
        <td align="center">
            <?
            if ($FirstRecNo>0)
                echo '<a href="showunselected.php?FirstRecNo=0">第一页</a>';
            else
                echo "第一页";
            ?>
        </td>
        <td align="center">
            <?php
            if ($FirstRecNo>$RecNumPerPage-1)
                echo "<a href='showunselected.php?FirstRecNo=".($FirstRecNo-$RecNumPerPage)."'>上一页</a>";
            else
                echo "上一页";
            ?>
        </td>
        <td align="center">
            <?php
            if ($Sum>$MaxRecNo)
                echo "<a href='showunselected.php?FirstRecNo=".($FirstRecNo+$RecNumPerPage)."'>下一页</a>";
            else
                echo "下一页";
            ?>
        </td>
        <td align="center">
            <?php
            if ($Sum>$MaxRecNo)
            {
                $final = floor(($Sum-1)/$RecNumPerPage)*$RecNumPerPage;
                echo "<a href='showunselected.php?FirstRecNo=$final'>最后一页</a>";
            }
            else
                echo "最后一页";
            ?>
        </td>
    </tr>
</table>
</center>
</body>
</html>
